package com.vtquang.mymaps.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.vtquang.mymaps.MyAddress;
import com.vtquang.mymaps.R;

public class SearchListAdapter extends BaseAdapter {

	private static ArrayList<MyAddress> itemDetailsrrayList;

	private LayoutInflater l_Inflater;

	public SearchListAdapter(Context context, ArrayList<MyAddress> results) {
		itemDetailsrrayList = results;
		l_Inflater = LayoutInflater.from(context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return itemDetailsrrayList.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return itemDetailsrrayList.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub

		ViewHolde holder;
		if (convertView == null) {
			convertView = l_Inflater.inflate(R.layout.search_row, null);
			holder = new ViewHolde();
			holder._name = (TextView) convertView.findViewById(R.id.tvName); 
			holder._local = (TextView) convertView.findViewById(R.id.tvLocal);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolde) convertView.getTag();
		}

		holder._name.setText(itemDetailsrrayList.get(position).get_name());
		holder._local.setText(itemDetailsrrayList.get(position).get_location());
		return convertView;
	}

	private class ViewHolde {
		public TextView _name;
		public TextView _local;
	} 
}
